//
//  LGCarePlanOtherCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/9/18.
//  照护计划 -- 其他（备注+描述）

#import "LGCarePlanCommonCell.h"
#import "LGCheckPhotoTool.h"
@interface LGCarePlanCommonCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *typeLabel;
/**  待确认标识 */
@property (nonatomic , strong)UILabel *sureTipLabel;
/**   */
@property (nonatomic , strong)UIButton *actionBtn;
/**   */
@property (nonatomic , strong)UILabel *dateLabel;
/**   */
@property (nonatomic , strong)UIView *lineView;
/**  患者意向入院 */
@property (nonatomic , strong)UILabel *desireDateTitle;
@property (nonatomic , strong)UILabel *desireDateLabel;
/**  安排入院时间 */
@property (nonatomic , strong)UILabel *appointDateTitle;
@property (nonatomic , strong)UILabel *appointDateLabel;
/**  描述 */
@property (nonatomic , strong)UILabel *descTitle;
@property (nonatomic , strong)UILabel *descLabel;
/**  备注 */
@property (nonatomic , strong)UILabel *remoarkTitle;
@property (nonatomic , strong)UILabel *remoarkLabel;

/**  其他科室-查看图片 */
@property (nonatomic , strong)UILabel *picLabel;
@property (nonatomic , strong)UIButton *picButton;

@end

@implementation LGCarePlanCommonCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    NSString *typeIcon = ([dataDic[@"task_type"] integerValue] == 5)?@"照护计划-其他科室":@"照护计划-描述";
    self.iconView.image = [UIImage imageNamed:typeIcon];
    self.typeLabel.text = LGNSString(dataDic[@"task_type_name"]);
    self.dateLabel.text = LGNSString(dataDic[@"task_date"]);
    //1排队中 3未完成 4已完成
    NSString *status = LGNSString(dataDic[@"task_status_admin"]);
    BOOL showPic = NO;
    if([status isEqualToString:@"4"]){
        //已完成
//        self.maskView.hidden = NO;
        self.actionBtn.titleLabel.font = LGFont(15);
        [self.actionBtn setTitleColor:[UIColor colorWithString:@"#666666"] forState:UIControlStateNormal];
        [self.actionBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        if([dataDic[@"task_type"] integerValue] == 5 && [dataDic[@"task_files"] count]>0){
            showPic = YES;
        }
    }else{
//        self.maskView.hidden = YES;
        self.actionBtn.titleLabel.font = LGFontWeight(15, UIFontWeightMedium);
        [self.actionBtn setTitleColor:[UIColor colorWithString:@"#3291FF"] forState:UIControlStateNormal];
        [self.actionBtn setImage:[UIImage imageNamed:@"grayTip12"] forState:UIControlStateNormal];
    }
    self.actionBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.actionBtn setTitle:LGNSString(dataDic[@"task_status_admin_name"]) forState:UIControlStateNormal];
    [self.actionBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:2];
    
    NSString *confirm = LGNSString(dataDic[@"task_status_confirm"]);
    NSString *backColor = [confirm isEqualToString:@"0"]?@"#F1F8FF":@"#FFFFFF";
    NSString *boaderColor = [confirm isEqualToString:@"0"]?@"#4C87FD":@"";
    self.baseView.backgroundColor = [UIColor colorWithString:backColor];
    self.baseView.layer.borderColor = [UIColor colorWithString:boaderColor].CGColor;
    NSString *tipTextColor = [confirm isEqualToString:@"0"]?@"#E3516B":@"#4C87FD";
    NSString *tipBackColor = [confirm isEqualToString:@"0"]?@"#FFDAE0":@"#DFEEFF";
    self.sureTipLabel.textColor = [UIColor colorWithString:tipTextColor];
    self.sureTipLabel.backgroundColor = [UIColor colorWithString:tipBackColor];
    NSString *tips = LGNSString(dataDic[@"tips"]);
    self.sureTipLabel.text = tips;
    CGFloat width = (tips.length>0)?[tips textWidthWithFont:LGFontWeight(12, UIFontWeightMedium) maxHeight:MAXFLOAT]+viewPix(24):0;
    [self.sureTipLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(width));
    }];
    
    NSString *desireDate = LGNSString(dataDic[@"desire_date"]);
    NSString *appointDate = LGNSString(dataDic[@"appointment_date"]);
    NSString *descString = LGNSString(dataDic[@"task_desc"]);
    NSString *remarkStr = LGNSString(dataDic[@"task_remark"]);
    
    
    //患者意向入院时间
    CGFloat desireTop = (desireDate.length>0)?viewPix(13):0;
    self.desireDateTitle.text = (desireDate.length>0)?@"患者意向入院":@"";
    self.desireDateLabel.text = desireDate;
    [self.desireDateTitle mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineView.mas_bottom).offset(desireTop);
    }];
    
    //安排入院时间
    CGFloat appointTop = (appointDate.length>0)?viewPix(13):0;
    self.appointDateTitle.text = (appointDate.length>0)?@"安排入院时间":@"";
    self.appointDateLabel.text = appointDate;
    [self.appointDateTitle mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.desireDateTitle.mas_bottom).offset(appointTop);
    }];
    
    //描述
    CGFloat descTop = (descString.length>0)?viewPix(13):0;
    self.descTitle.text = (descString.length>0)?@"描述":@"";
    self.descLabel.text = descString;
    [self.descTitle mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.appointDateTitle.mas_bottom).offset(descTop);
    }];
    
    //备注
    CGFloat remarkTop = (remarkStr.length>0)?viewPix(13):0;
    CGFloat picBottom = (showPic == YES)?-viewPix(37):0;
    CGFloat remarkBottom = (desireDate.length == 0 && appointDate.length == 0 && descString.length == 0 && remarkStr.length==0) ? 1 : -viewPix(12);
    self.remoarkTitle.text = (remarkStr.length>0)?@"备注":@"";
    self.remoarkLabel.text = remarkStr;
    [self.remoarkLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.descLabel.mas_bottom).offset(remarkTop);
        make.bottom.equalTo(self.baseView).offset(remarkBottom+picBottom);
    }];
    
    self.picLabel.hidden = !showPic;
    self.picButton.hidden = !showPic;
}

//查看图片
-(void)checkPickAction{
    LGCheckPhotoTool *photoView = [[LGCheckPhotoTool alloc]initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H)];
    photoView.picArray = self.dataDic[@"task_files"];
    photoView.title = @"";
    [[UIApplication sharedApplication].keyWindow addSubview:photoView];
    [photoView showViewAnimation:CGPointMake(Screen_W/2.0, Screen_H/2.0) index:0];
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
//    [self.contentView addSubview:self.maskView];
    [self.baseView addSubview:self.iconView];
    [self.baseView addSubview:self.typeLabel];
    [self.baseView addSubview:self.sureTipLabel];
    [self.baseView addSubview:self.actionBtn];
    [self.baseView addSubview:self.dateLabel];
    [self.baseView addSubview:self.lineView];
    [self.baseView addSubview:self.desireDateTitle];
    [self.baseView addSubview:self.desireDateLabel];
    [self.baseView addSubview:self.appointDateTitle];
    [self.baseView addSubview:self.appointDateLabel];
    [self.baseView addSubview:self.descTitle];
    [self.baseView addSubview:self.descLabel];
    [self.baseView addSubview:self.remoarkTitle];
    [self.baseView addSubview:self.remoarkLabel];
    [self.baseView addSubview:self.picLabel];
    [self.baseView addSubview:self.picButton];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(8));
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.bottom.equalTo(self.contentView).offset(-viewPix(8));
    }];
//    [self.maskView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.bottom.right.equalTo(self.baseView);
//    }];
    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.iconView);
    }];
    [self.sureTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.typeLabel.mas_right).offset(viewPix(8));
        make.centerY.equalTo(self.typeLabel);
        make.height.equalTo(@(viewPix(18)));
        make.width.equalTo(@(0));
    }];
    [self.actionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.typeLabel);
        make.width.equalTo(@(viewPix(65)));
        make.height.equalTo(@(viewPix(25)));
    }];
    [self.desireDateTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineView.mas_bottom).offset(viewPix(13));
        make.left.equalTo(self.baseView).offset(viewPix(12));
    }];
    [self.desireDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.desireDateTitle);
    }];
    
    [self.appointDateTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.desireDateTitle.mas_bottom).offset(viewPix(12));
        make.left.equalTo(self.desireDateTitle);
    }];
    [self.appointDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.desireDateLabel);
        make.centerY.equalTo(self.appointDateTitle);
    }];
    
    [self.descTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.appointDateTitle.mas_bottom).offset(viewPix(12));
        make.left.equalTo(self.desireDateTitle);
    }];
    [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(viewPix(50));
        make.right.equalTo(self.desireDateLabel);
        make.top.equalTo(self.descTitle);
    }];
    
    [self.remoarkTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.descLabel.mas_bottom).offset(viewPix(12));
        make.left.equalTo(self.desireDateTitle);
    }];
    [self.remoarkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(viewPix(50));
        make.right.equalTo(self.desireDateLabel);
        make.top.equalTo(self.remoarkTitle);
        make.bottom.equalTo(self.baseView).offset(-viewPix(12));
    }];
    
    [self.picLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.picButton);
        make.left.equalTo(self.desireDateTitle);
    }];
    [self.picButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.remoarkLabel.mas_bottom).offset(viewPix(12));
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.left.right.equalTo(self.baseView);
        make.height.equalTo(@(viewPix(25)));
    }];
    
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.layer.borderWidth = 1;
        _baseView.cornerRidus = 15;
    }
    return _baseView;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"照护计划-体征监测"]];
        _iconView.frame = CGRectMake(viewPix(12), viewPix(12), viewPix(24), viewPix(24));
    }
    return _iconView;
}

-(UILabel *)typeLabel{
    if(!_typeLabel){
        _typeLabel = [UILabel lableWithText:@"复诊复查" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _typeLabel;
}

-(UILabel *)sureTipLabel{
    if(!_sureTipLabel){
        _sureTipLabel = [UILabel lableWithText:@"" colorString:@"#4C87FD" textFont:LGFontWeight(12, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _sureTipLabel.backgroundColor = [UIColor colorWithString:@"#DFEEFF"];
        _sureTipLabel.cornerRidus = viewPix(9);
    }
    return _sureTipLabel;
}

-(UIButton *)actionBtn{
    if(!_actionBtn){
        _actionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _actionBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _actionBtn.userInteractionEnabled = NO;
    }
    return _actionBtn;
}

-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
        _dateLabel.frame = CGRectMake(viewPix(12), viewPix(40), Screen_W-viewPix(56), viewPix(21));
    }
    return _dateLabel;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(viewPix(12), viewPix(74), Screen_W-viewPix(56), 0.5)];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E8E8E8"];
    }
    return _lineView;
}

-(UILabel *)desireDateTitle{
    if(!_desireDateTitle){
        _desireDateTitle = [UILabel lableWithText:@"患者意向入院" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _desireDateTitle;
}

-(UILabel *)desireDateLabel{
    if(!_desireDateLabel){
        _desireDateLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _desireDateLabel;
}

-(UILabel *)appointDateTitle{
    if(!_appointDateTitle){
        _appointDateTitle = [UILabel lableWithText:@"安排入院时间" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _appointDateTitle;
}

-(UILabel *)appointDateLabel{
    if(!_appointDateLabel){
        _appointDateLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _appointDateLabel;
}

-(UILabel *)descTitle{
    if(!_descTitle){
        _descTitle = [UILabel lableWithText:@"描述" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _descTitle;
}

-(UILabel *)descLabel{
    if(!_descLabel){
        _descLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentRight lines:0];
    }
    return _descLabel;
}

-(UILabel *)remoarkTitle{
    if(!_remoarkTitle){
        _remoarkTitle = [UILabel lableWithText:@"备注" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _remoarkTitle;
}

-(UILabel *)remoarkLabel{
    if(!_remoarkLabel){
        _remoarkLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentRight lines:0];
    }
    return _remoarkLabel;
}

-(UILabel *)picLabel{
    if(!_picLabel){
        _picLabel = [UILabel lableWithText:@"患者上传图片" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _picLabel;
}

-(UIButton *)picButton{
    if(!_picButton){
        _picButton = [UIButton buttonWithTitle:@"查看" titleFont:LGFont(15) textColor:@"#666666" imageName:@"grayTip12"];
        _picButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _picButton.bounds = CGRectMake(0, 0, Screen_W-viewPix(32), viewPix(25));
        [_picButton setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:0];
        [_picButton addTarget:self action:@selector(checkPickAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _picButton;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
